<template>
  <div class="admin-dashboard">
    <div class="admin-header">
      <h1>动物乐园后台管理系统</h1>
      <div class="header-actions">
        <span class="welcome-text">欢迎管理员</span>
        <button @click="logout" class="logout-btn">退出登录</button>
      </div>
    </div>
    
    <div class="admin-layout">
      <aside class="sidebar">
        <nav class="admin-nav">
          <ul>
            <li>
              <router-link to="/admin/dashboard" class="nav-item" active-class="active">
                <span class="nav-icon">📊</span>
                <span class="nav-text">仪表盘</span>
              </router-link>
            </li>
            <li>
              <router-link to="/admin/animals" class="nav-item" active-class="active">
                <span class="nav-icon">🐾</span>
                <span class="nav-text">动物管理</span>
              </router-link>
            </li>
            <li>
              <router-link to="/admin/categories" class="nav-item" active-class="active">
                <span class="nav-icon">📂</span>
                <span class="nav-text">分类管理</span>
              </router-link>
            </li>
            <li>
              <router-link to="/admin/users" class="nav-item" active-class="active">
                <span class="nav-icon">👥</span>
                <span class="nav-text">用户管理</span>
              </router-link>
            </li>
          </ul>
        </nav>
      </aside>
      
      <main class="main-content">
        <div class="dashboard-overview">
          <h2>系统概览</h2>
          <div class="stats-grid">
            <div class="stat-card">
              <div class="stat-icon">🐾</div>
              <div class="stat-content">
                <h3>动物总数</h3>
                <p class="stat-number">{{ stats.animalCount }}</p>
              </div>
            </div>
            <div class="stat-card">
              <div class="stat-icon">📂</div>
              <div class="stat-content">
                <h3>分类总数</h3>
                <p class="stat-number">{{ stats.categoryCount }}</p>
              </div>
            </div>
            <div class="stat-card">
              <div class="stat-icon">👥</div>
              <div class="stat-content">
                <h3>用户总数</h3>
                <p class="stat-number">{{ stats.userCount }}</p>
              </div>
            </div>
            <div class="stat-card">
              <div class="stat-icon">💖</div>
              <div class="stat-content">
                <h3>总点赞数</h3>
                <p class="stat-number">{{ stats.totalLikes }}</p>
              </div>
            </div>
          </div>
        </div>
        
        <div class="dashboard-section">
          <h2>最近更新</h2>
          <div class="recent-activity">
            <p>暂无更新记录</p>
          </div>
        </div>
      </main>
    </div>
  </div>
</template>

<script>
export default {
  name: 'DashboardView',
  data() {
    return {
      stats: {
        animalCount: 0,
        categoryCount: 0,
        userCount: 0,
        totalLikes: 0
      }
    }
  },
  mounted() {
    this.fetchDashboardStats()
  },
  methods: {
    fetchDashboardStats() {
      // 模拟数据，实际应该从API获取
      this.stats = {
        animalCount: 42,
        categoryCount: 8,
        userCount: 128,
        totalLikes: 512
      }
    },
    logout() {
      localStorage.removeItem('user')
      this.$router.push('/login')
    }
  }
}
</script>

<style scoped>
.admin-dashboard {
  min-height: 100vh;
  background-color: #f5f7fa;
}

.admin-header {
  background-color: #2c3e50;
  color: white;
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.admin-header h1 {
  margin: 0;
  font-size: 1.5rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.welcome-text {
  font-size: 0.9rem;
  opacity: 0.9;
}

.logout-btn {
  background-color: #e74c3c;
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background-color 0.2s;
}

.logout-btn:hover {
  background-color: #c0392b;
}

.admin-layout {
  display: flex;
  min-height: calc(100vh - 60px);
}

.sidebar {
  width: 250px;
  background-color: #34495e;
  color: white;
}

.admin-nav ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  padding: 1rem 1.5rem;
  color: white;
  text-decoration: none;
  transition: background-color 0.2s;
  gap: 1rem;
}

.nav-item:hover {
  background-color: #2c3e50;
}

.nav-item.active {
  background-color: #1abc9c;
}

.nav-icon {
  font-size: 1.2rem;
}

.main-content {
  flex: 1;
  padding: 2rem;
}

.dashboard-overview h2,
.dashboard-section h2 {
  margin-top: 0;
  color: #2c3e50;
  font-size: 1.4rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
  margin-top: 1.5rem;
}

.stat-card {
  background-color: white;
  padding: 1.5rem;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.stat-icon {
  font-size: 2.5rem;
}

.stat-content h3 {
  margin: 0;
  color: #7f8c8d;
  font-size: 0.9rem;
  font-weight: normal;
}

.stat-number {
  margin: 0.5rem 0 0 0;
  font-size: 1.8rem;
  font-weight: bold;
  color: #2c3e50;
}

.dashboard-section {
  margin-top: 2rem;
  background-color: white;
  padding: 1.5rem;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.recent-activity {
  color: #7f8c8d;
  text-align: center;
  padding: 2rem;
}

@media (max-width: 768px) {
  .admin-layout {
    flex-direction: column;
  }
  
  .sidebar {
    width: 100%;
  }
  
  .admin-nav ul {
    display: flex;
    overflow-x: auto;
  }
  
  .nav-item {
    white-space: nowrap;
    flex-shrink: 0;
  }
}
</style>